package com.yanqu.road.entity.activity.biaoju;

import com.yanqu.road.entity.DataObject;
import com.yanqu.road.entity.FieldTypeAnnotation;
import com.yanqu.road.utils.date.DateHelper;
import com.yanqu.road.utils.property.Property;
import org.apache.mina.util.ConcurrentHashSet;

import java.math.BigDecimal;
import java.util.*;
import java.util.concurrent.ConcurrentHashMap;

@FieldTypeAnnotation(tableName = "t_c_biaoju", desc = "镖局数据")
public class CrossBiaoJuData extends DataObject {
    @FieldTypeAnnotation(select = true, update = true, isIndex = true)
    private int activityId;
    @FieldTypeAnnotation(select = true, update = true, isIndex = true, desc = "商会分组")
    private int unionGroup;
    @FieldTypeAnnotation(desc = "当前轮")
    private int nowRound;
    @FieldTypeAnnotation(desc = "已结算的轮次")
    private int settleRound;
    @FieldTypeAnnotation(desc = "当前优质镖品质")
    private List<Integer> bestQualityList = new ArrayList<>();
    @FieldTypeAnnotation(desc = "每轮的玩家等级统计key1 round key2 titleId")
    private Map<Integer, Map<Integer, Integer>> historyLevelAmountMap = new ConcurrentHashMap<>();
    @FieldTypeAnnotation(desc = "每轮计算的结果key1 round key2 dartLevel")
    private Map<Integer, Map<Integer, BigDecimal>> historyCalcResultMap = new ConcurrentHashMap<>();

    public CrossBiaoJuData(int activityId, int unionGroup) {
        this.activityId = activityId;
        this.unionGroup = unionGroup;
        setInsertOption();
    }

    public CrossBiaoJuData() {
    }

    public int getActivityId() {
        return activityId;
    }

    public void setActivityId(int activityId) {
        this.activityId = activityId;
    }

    public int getUnionGroup() {
        return unionGroup;
    }

    public void setUnionGroup(int unionGroup) {
        this.unionGroup = unionGroup;
    }

    public int getNowRound() {
        return nowRound;
    }

    public void setNowRound(int nowRound) {
        if (this.nowRound != nowRound) {
            this.nowRound = nowRound;
            setUpdateOption();
        }
    }

    public List<Integer> getBestQualityList() {
        return bestQualityList;
    }

    public void setBestQualityList(List<Integer> bestQualityList) {
        this.bestQualityList = bestQualityList;
        setUpdateOption();
    }

    public Map<Integer, Map<Integer, Integer>> getHistoryLevelAmountMap() {
        return historyLevelAmountMap;
    }

    public void setHistoryLevelAmountMap(Map<Integer, Map<Integer, Integer>> historyLevelAmountMap) {
        this.historyLevelAmountMap = historyLevelAmountMap;
        setUpdateOption();
    }

    public Map<Integer, Map<Integer, BigDecimal>> getHistoryCalcResultMap() {
        return historyCalcResultMap;
    }

    public void setHistoryCalcResultMap(Map<Integer, Map<Integer, BigDecimal>> historyCalcResultMap) {
        this.historyCalcResultMap = historyCalcResultMap;
        setUpdateOption();
    }

    public int getSettleRound() {
        return settleRound;
    }

    public void setSettleRound(int settleRound) {
        if (this.settleRound != settleRound) {
            this.settleRound = settleRound;
            setUpdateOption();
        }
    }

    public void updateHistoryLevelAmount(int round, Map<Integer, Integer> numMap, Map<Integer, BigDecimal> calcMap) {
        this.historyLevelAmountMap.put(round, numMap);
        this.historyCalcResultMap.put(round, calcMap);
        setUpdateOption();
    }

    public Map<Integer, BigDecimal> getRoundCalcResult(int round) {
        Map<Integer, BigDecimal> resultMap = this.historyCalcResultMap.get(round);
        if (resultMap == null) {
            return new HashMap<>();
        }
        return resultMap;
    }

    public BigDecimal getRoundCalcResult(int round, int quality) {
        Map<Integer, BigDecimal> resultMap = this.historyCalcResultMap.get(round);
        if (resultMap == null) {
            return BigDecimal.ZERO;
        }
        return resultMap.getOrDefault(quality, BigDecimal.ZERO);
    }

    public boolean isBestQuality(int quality) {
        for (int compareValue : this.bestQualityList) {
            if (compareValue == quality) {
                return true;
            }
        }

        return false;
    }

}
